import java.awt.*;
import java.util.*;
import java.text.*;
import javax.swing.*;
import javax.swing.text.*;
public class JFormattedTextFieldDemo extends JFrame
{
	
	public JFormattedTextFieldDemo() throws Exception{
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100,100,300,200);
		setTitle("TITLE");
		Container c = getContentPane();
		
		getContentPane().setLayout(new GridLayout(3,2));
		
		c.add(new JLabel("日期:"));	
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy--MM--dd");	
		DateFormatter df = new DateFormatter(sdf);
		JFormattedTextField txt1 = new JFormattedTextField(df);
		txt1.setValue(new Date());

		c.add(txt1);

		c.add(new JLabel("数字:"));	

		MaskFormatter mf1 = new MaskFormatter("###-##-###");
		mf1.setPlaceholderCharacter('_');
		JFormattedTextField txt2 = new JFormattedTextField(mf1);
		c.add(txt2);

	}
	public static void main(String[] args) throws Exception{
		new JFormattedTextFieldDemo().setVisible(true);	
	}
}
